package controller;

import pojo.PageBean;
import pojo.Product;
import service.ProductService;
import service.impl.ProductServiceimpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author LiangHaiBo
 * @version 1.0
 * @date 2021.9.7 下午 19:32
 */
@WebServlet("/product")
public class ProductServlet extends BaseServlet{
    public  String getProduct(HttpServletRequest request,HttpServletResponse response){

        String pid = request.getParameter("pid");
        ProductService productService = new ProductServiceimpl();
        Product product = productService.getProductById(pid) ;

        request.setAttribute("product",product);
        return "/jsp/product_info.jsp";

    }
    
    public String findProductByPage(HttpServletRequest request,HttpServletResponse response){
        //接收前台参数
        String curPage = request.getParameter("currentPage");
        int currentPage = Integer.parseInt(curPage);

        String cid = request.getParameter("cid");

        int pageSize = 12;
        //调用业务接口
        ProductService productService = new ProductServiceimpl();
        PageBean<Product> pb = productService.getProductByPage(currentPage,pageSize,cid);

        request.setAttribute("pb",pb);

        return "/jsp/product_list.jsp";
    }
}
